package cn.gson.springboot.model.service;


import cn.gson.springboot.model.dao.CustomerCareDao;
import cn.gson.springboot.model.mapper.CustomerCareMapper;
import cn.gson.springboot.model.pojos.Customercare;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class CustomerCareService {
    @Autowired
    CustomerCareDao customerCareDao;
    @Autowired
    CustomerCareMapper customerCareMapper;

    //新增
    public void addCustomercare(Customercare customercare){
        customerCareDao.save(customercare);//一次保存一个对象
    }

    //删除
    public void deleteOne(int customercareId){
        customerCareDao.deleteById(customercareId);
    }

    //查找所有
    public List<Customercare> selectAll( String search,Integer type){
        return (List<Customercare>)customerCareMapper.selectAll(search,type);
    }


    //根据id修改
    public void alter(int customercareId,Customercare customercare){
         if ( customerCareDao.findById(customercareId)!=null){//找到该对象
             Customercare customercare1=customerCareDao.findById(customercareId).get();
             customercare1.setCustomercareTheme(customercare.getCustomercareTheme());
             customerCareDao.save(customercare1);
         }
    }
}
